<?php
/**
 * 后台操作日志对列
 */

namespace app\queue\redis;

use Exception;
use plugin\admin\app\model\AdminLog;
use support\Log;
use Webman\RedisQueue\Consumer;

class ConverterSendAdminLog implements Consumer
{
    // 要消费的队列名
    public string $queue = 'converter_admin_log_list';

    // 连接名，对应 config/redis_queue.php 里的连接`
    public string $connection = 'default';

    // 消费

    /**
     * 自动消费
     *
     * 队列生产 $contact = [
     * 'title' => $i,
     * ];
     * $a = RedisQueueService::instance()->_send($contact);
     *
     * @throws Exception
     */
    public function consume($data)
    {
        AdminLog::insert([
            'admin_id'     => $data['admin_id'],
            'request_type' => $data['request_type'],
            'route'        => $data['route'],
            'ip'           => $data['ip'],
            'request_data' => $data['request_data'],
            'return_data'  => $data['return_data'],
            'type'         => $data['type'],
            'table'        => $data['table'],
            'table_id'     => $data['table_id'],
            'log'          => $data['log'],
            'status'       => $data['status'],
            'created_at'   => $data['created_at'],
        ]);
    }
}